package com.tos.utils;

import com.tos.slidepuzzle.R;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.database.Cursor;
import android.net.Uri;
import android.preference.PreferenceManager;
import android.provider.MediaStore;

public class Utils {
	public static String getPath(Activity a, Uri uri) {
		String[] projection = { MediaStore.Images.Media.DATA };
		Cursor cursor = a.managedQuery(uri, projection, null, null, null);
		int column_index = cursor
				.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
		cursor.moveToFirst();
		return cursor.getString(column_index);
	}

	public static boolean putBooleanValue(Context context, String key,
			boolean value) {
		return PreferenceManager.getDefaultSharedPreferences(context).edit()
				.putBoolean(key, value).commit();

	}

	public static final boolean getBooleanValue(Context context, String key) {
		return PreferenceManager.getDefaultSharedPreferences(context)
				.getBoolean(key, true);
	}

	public static final boolean putBackgroundColor(Context context, String key,
			int value) {
		return PreferenceManager.getDefaultSharedPreferences(context).edit()
				.putInt(key, value).commit();
	}

	public static final int getBackgroundColor(Context context, String key) {
		return PreferenceManager.getDefaultSharedPreferences(context).getInt(
				key, R.color.background_gray);
	}

	public static final boolean putStringValue(Context context, String key,
			String value) {
		return PreferenceManager.getDefaultSharedPreferences(context).edit()
				.putString(key, value).commit();
	}

	public static final String getStringValue(Context context, String key) {
		return PreferenceManager.getDefaultSharedPreferences(context)
				.getString(key, "");
	}

	public static void showAlertMessage(Context context,String message) {
		final AlertDialog.Builder builder = new AlertDialog.Builder(context);
		builder.setMessage(message).setCancelable(false)
				.setPositiveButton("OK", new DialogInterface.OnClickListener() 
				{
					public void onClick(final DialogInterface dialog,
							final int id) 
					{

					}
				});
		final AlertDialog alert = builder.create();
		alert.show();

	}
}
